package com.lemon.gateway.filter;

import com.lemon.redis.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
 * @author 李猛
 * @datetime 2024/2/15 22:23
 * @description 类对象
 */
@Slf4j
@Component
public class AuthFilter implements GlobalFilter, Ordered {
    @Resource
    private RedisService redisService;

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        ServerHttpResponse response = exchange.getResponse();

        //uri
        String uri = request.getURI().getPath();
        log.info("权限过滤器,uri:{}", uri);
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        //过滤器的顺序，数值越大优先级越低
        return 0;
    }
}
